#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  08-noSynFlood-lv4.sh
# Version	:  1.0
# Date		:  2020/05/14
# Author	:  Lz
# Email		:  lz843723683@gmail.com
# History	:     
#             Version 1.0, 2020/05/14
# Function	:   packages - 07.测试安全四级-禁止syn flood攻击
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

## TODO : 测试收尾清除工作
#
NOSYNFLOODClean_FTLV4(){
	return $TPASS
}


## TODO: 调用程序退出函数
#    In: $1 => 调用脚本结果值
NOSYNFLOODExit_FTLV4(){
        # 调用退出函数，其中调用了clean相关函数
	Exit_FTLIB ${1}
}


## TODO: 用户界面
#
NOSYNFLOODUSAGE_FTLV4(){
	USAGE_FTLIB "安全四级测试 - 禁止syn flood攻击"
}


## TODO : 测试前的初始化 
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other=> TCONF
NOSYNFLOODInit_FTLV4(){
        # 调用初始化函数
	Init_FTLIB "NOSYNFLOODClean_FTLV4"
        # 调用用户界面函数
 	NOSYNFLOODUSAGE_FTLV4
}


## TODO ：禁止syn flood攻击
#
NOSYNFLOODTest01_FTLV4(){
	local ret="$TPASS"

        local flag="net.ipv4.tcp_syncookies = 1"
	local cmd="sysctl -p"

	eval $cmd | grep -q "$flag"
	if [ $? -ne 0 ];then
		ret=$TFAIL
	fi

	echo "Command : $cmd"
	eval $cmd
        if [ $ret -eq $TFAIL ];then
                # 失败，未找到对应配置
                echo "未找到配置: $flag"
        fi

	OutputRet_FTLIB ${ret}
        RetParse_FTLIB "禁止syn flood攻击. 存在${flag}" "False"
}


## TODO : Main
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other => TCONF
NOSYNFLOODMain_FTLV4(){
	NOSYNFLOODInit_FTLV4

	NOSYNFLOODTest01_FTLV4

	return ${TPASS}	
}

NOSYNFLOODMain_FTLV4
NOSYNFLOODExit_FTLV4 $?
